#include "StdAfx.h"
#include "deadZ80.h"
#include "opcodes.h"

int CDeadZ80::ExecuteOpcodeDDCB()
{
	unsigned char data = ReadMemory8(pc++);
	unsigned char opcode = ReadMemory8(pc++);
	unsigned short stmp;
	unsigned char tmp;
	unsigned long ltmp;

	ltmp = (unsigned int)(unsigned short)((signed short)IX + (signed char)data);	\
	switch(opcode) {
		case 0x06: tmp = ReadMemory8(ltmp); RLC(tmp); WriteMemory8(ltmp,tmp); break; //rlc (ix+n)
		case 0x0E: tmp = ReadMemory8(ltmp); RRC(tmp); WriteMemory8(ltmp,tmp); break; //rrc (ix+n)
		case 0x16: tmp = ReadMemory8(ltmp); RL(tmp); WriteMemory8(ltmp,tmp); break; //rl (ix+n)
		case 0x1E: tmp = ReadMemory8(ltmp); RR(tmp); WriteMemory8(ltmp,tmp); break; //rr (ix+n)
		case 0x26: tmp = ReadMemory8(ltmp); SLA(tmp); WriteMemory8(ltmp,tmp); break; //sla (ix+n)
		case 0x2E: tmp = ReadMemory8(ltmp); SRA(tmp); WriteMemory8(ltmp,tmp); break; //sra (ix+n)
		case 0x36: tmp = ReadMemory8(ltmp); SLL(tmp); WriteMemory8(ltmp,tmp); break; //sla (ix+n)
		case 0x3E: tmp = ReadMemory8(ltmp); SRL(tmp); WriteMemory8(ltmp,tmp); break; //sra (ix+n)
		case 0x40:	BIT_IDX(0);							break;	//bit 0,(ix+n)
		case 0x41:	BIT_IDX(0);							break;	//bit 0,(ix+n)
		case 0x42:	BIT_IDX(0);							break;	//bit 0,(ix+n)
		case 0x43:	BIT_IDX(0);							break;	//bit 0,(ix+n)
		case 0x44:	BIT_IDX(0);							break;	//bit 0,(ix+n)
		case 0x45:	BIT_IDX(0);							break;	//bit 0,(ix+n)
		case 0x46:	BIT_IDX(0);							break;	//bit 0,(ix+n)
		case 0x47:	BIT_IDX(0);							break;	//bit 0,(ix+n)
		case 0x48:	BIT_IDX(1);							break;	//bit 1,(ix+n)
		case 0x49:	BIT_IDX(1);							break;	//bit 1,(ix+n)
		case 0x4A:	BIT_IDX(1);							break;	//bit 1,(ix+n)
		case 0x4B:	BIT_IDX(1);							break;	//bit 1,(ix+n)
		case 0x4C:	BIT_IDX(1);							break;	//bit 1,(ix+n)
		case 0x4D:	BIT_IDX(1);							break;	//bit 1,(ix+n)
		case 0x4E:	BIT_IDX(1);							break;	//bit 1,(ix+n)
		case 0x4F:	BIT_IDX(1);							break;	//bit 1,(ix+n)
		case 0x50:	BIT_IDX(2);							break;	//bit 2,(ix+n)
		case 0x51:	BIT_IDX(2);							break;	//bit 2,(ix+n)
		case 0x52:	BIT_IDX(2);							break;	//bit 2,(ix+n)
		case 0x53:	BIT_IDX(2);							break;	//bit 2,(ix+n)
		case 0x54:	BIT_IDX(2);							break;	//bit 2,(ix+n)
		case 0x55:	BIT_IDX(2);							break;	//bit 2,(ix+n)
		case 0x56:	BIT_IDX(2);							break;	//bit 2,(ix+n)
		case 0x57:	BIT_IDX(2);							break;	//bit 2,(ix+n)
		case 0x58:	BIT_IDX(3);							break;	//bit 3,(ix+n)
		case 0x59:	BIT_IDX(3);							break;	//bit 3,(ix+n)
		case 0x5A:	BIT_IDX(3);							break;	//bit 3,(ix+n)
		case 0x5B:	BIT_IDX(3);							break;	//bit 3,(ix+n)
		case 0x5C:	BIT_IDX(3);							break;	//bit 3,(ix+n)
		case 0x5D:	BIT_IDX(3);							break;	//bit 3,(ix+n)
		case 0x5E:	BIT_IDX(3);							break;	//bit 3,(ix+n)
		case 0x5F:	BIT_IDX(3);							break;	//bit 3,(ix+n)
		case 0x60:	BIT_IDX(4);							break;	//bit 4,(ix+n)
		case 0x61:	BIT_IDX(4);							break;	//bit 4,(ix+n)
		case 0x62:	BIT_IDX(4);							break;	//bit 4,(ix+n)
		case 0x63:	BIT_IDX(4);							break;	//bit 4,(ix+n)
		case 0x64:	BIT_IDX(4);							break;	//bit 4,(ix+n)
		case 0x65:	BIT_IDX(4);							break;	//bit 4,(ix+n)
		case 0x66:	BIT_IDX(4);							break;	//bit 4,(ix+n)
		case 0x67:	BIT_IDX(4);							break;	//bit 4,(ix+n)
		case 0x68:	BIT_IDX(5);							break;	//bit 5,(ix+n)
		case 0x69:	BIT_IDX(5);							break;	//bit 5,(ix+n)
		case 0x6A:	BIT_IDX(5);							break;	//bit 5,(ix+n)
		case 0x6B:	BIT_IDX(5);							break;	//bit 5,(ix+n)
		case 0x6C:	BIT_IDX(5);							break;	//bit 5,(ix+n)
		case 0x6D:	BIT_IDX(5);							break;	//bit 5,(ix+n)
		case 0x6E:	BIT_IDX(5);							break;	//bit 5,(ix+n)
		case 0x6F:	BIT_IDX(5);							break;	//bit 5,(ix+n)
		case 0x70:	BIT_IDX(6);							break;	//bit 6,(ix+n)
		case 0x71:	BIT_IDX(6);							break;	//bit 6,(ix+n)
		case 0x72:	BIT_IDX(6);							break;	//bit 6,(ix+n)
		case 0x73:	BIT_IDX(6);							break;	//bit 6,(ix+n)
		case 0x74:	BIT_IDX(6);							break;	//bit 6,(ix+n)
		case 0x75:	BIT_IDX(6);							break;	//bit 6,(ix+n)
		case 0x76:	BIT_IDX(6);							break;	//bit 6,(ix+n)
		case 0x77:	BIT_IDX(6);							break;	//bit 6,(ix+n)
		case 0x78:	BIT_IDX(7);							break;	//bit 7,(ix+n)
		case 0x79:	BIT_IDX(7);							break;	//bit 7,(ix+n)
		case 0x7A:	BIT_IDX(7);							break;	//bit 7,(ix+n)
		case 0x7B:	BIT_IDX(7);							break;	//bit 7,(ix+n)
		case 0x7C:	BIT_IDX(7);							break;	//bit 7,(ix+n)
		case 0x7D:	BIT_IDX(7);							break;	//bit 7,(ix+n)
		case 0x7E:	BIT_IDX(7);							break;	//bit 7,(ix+n)
		case 0x7F:	BIT_IDX(7);							break;	//bit 7,(ix+n)
		case 0x80:	RES_IDX(0);	B = tmp;				break;	//res 0,(ix+n),b
		case 0x81:	RES_IDX(0);	C = tmp;				break;	//res 0,(ix+n),c
		case 0x82:	RES_IDX(0);	D = tmp;				break;	//res 0,(ix+n),d
		case 0x83:	RES_IDX(0);	E = tmp;				break;	//res 0,(ix+n),e
		case 0x84:	RES_IDX(0);	H = tmp;				break;	//res 0,(ix+n),h
		case 0x85:	RES_IDX(0);	L = tmp;				break;	//res 0,(ix+n),l
		case 0x86:	RES_IDX(0);							break;	//res 0,(ix+n)
		case 0x87:	RES_IDX(0);	A = tmp;				break;	//res 0,(ix+n),a
		case 0x88:	RES_IDX(1);	B = tmp;				break;	//res 1,(ix+n),b
		case 0x89:	RES_IDX(1);	C = tmp;				break;	//res 1,(ix+n),c
		case 0x8A:	RES_IDX(1);	D = tmp;				break;	//res 1,(ix+n),d
		case 0x8B:	RES_IDX(1);	E = tmp;				break;	//res 1,(ix+n),e
		case 0x8C:	RES_IDX(1);	H = tmp;				break;	//res 1,(ix+n),h
		case 0x8D:	RES_IDX(1);	L = tmp;				break;	//res 1,(ix+n),l
		case 0x8E:	RES_IDX(1);							break;	//res 1,(ix+n)
		case 0x8F:	RES_IDX(1);	A = tmp;				break;	//res 1,(ix+n),a
		case 0x90:	RES_IDX(2);	B = tmp;				break;	//res 2,(ix+n),b
		case 0x91:	RES_IDX(2);	C = tmp;				break;	//res 2,(ix+n),c
		case 0x92:	RES_IDX(2);	D = tmp;				break;	//res 2,(ix+n),d
		case 0x93:	RES_IDX(2);	E = tmp;				break;	//res 2,(ix+n),e
		case 0x94:	RES_IDX(2);	H = tmp;				break;	//res 2,(ix+n),h
		case 0x95:	RES_IDX(2);	L = tmp;				break;	//res 2,(ix+n),l
		case 0x96:	RES_IDX(2);							break;	//res 2,(ix+n)
		case 0x97:	RES_IDX(2);	A = tmp;				break;	//res 2,(ix+n),a
		case 0x98:	RES_IDX(3);	B = tmp;				break;	//res 3,(ix+n),b
		case 0x99:	RES_IDX(3);	C = tmp;				break;	//res 3,(ix+n),c
		case 0x9A:	RES_IDX(3);	D = tmp;				break;	//res 3,(ix+n),d
		case 0x9B:	RES_IDX(3);	E = tmp;				break;	//res 3,(ix+n),e
		case 0x9C:	RES_IDX(3);	H = tmp;				break;	//res 3,(ix+n),h
		case 0x9D:	RES_IDX(3);	L = tmp;				break;	//res 3,(ix+n),l
		case 0x9E:	RES_IDX(3);							break;	//res 3,(ix+n)
		case 0x9F:	RES_IDX(3);	A = tmp;				break;	//res 3,(ix+n),a
		case 0xA0:	RES_IDX(4);	B = tmp;				break;	//res 4,(ix+n),b
		case 0xA1:	RES_IDX(4);	C = tmp;				break;	//res 4,(ix+n),c
		case 0xA2:	RES_IDX(4);	D = tmp;				break;	//res 4,(ix+n),d
		case 0xA3:	RES_IDX(4);	E = tmp;				break;	//res 4,(ix+n),e
		case 0xA4:	RES_IDX(4);	H = tmp;				break;	//res 4,(ix+n),h
		case 0xA5:	RES_IDX(4);	L = tmp;				break;	//res 4,(ix+n),l
		case 0xA6:	RES_IDX(4);							break;	//res 4,(ix+n)
		case 0xA7:	RES_IDX(4);	A = tmp;				break;	//res 4,(ix+n),a
		case 0xA8:	RES_IDX(5);	B = tmp;				break;	//res 5,(ix+n),b
		case 0xA9:	RES_IDX(5);	C = tmp;				break;	//res 5,(ix+n),c
		case 0xAA:	RES_IDX(5);	D = tmp;				break;	//res 5,(ix+n),d
		case 0xAB:	RES_IDX(5);	E = tmp;				break;	//res 5,(ix+n),e
		case 0xAC:	RES_IDX(5);	H = tmp;				break;	//res 5,(ix+n),h
		case 0xAD:	RES_IDX(5);	L = tmp;				break;	//res 5,(ix+n),l
		case 0xAE:	RES_IDX(5);							break;	//res 5,(ix+n)
		case 0xAF:	RES_IDX(5);	A = tmp;				break;	//res 5,(ix+n),a
		case 0xB0:	RES_IDX(6);	B = tmp;				break;	//res 6,(ix+n),b
		case 0xB1:	RES_IDX(6);	C = tmp;				break;	//res 6,(ix+n),c
		case 0xB2:	RES_IDX(6);	D = tmp;				break;	//res 6,(ix+n),d
		case 0xB3:	RES_IDX(6);	E = tmp;				break;	//res 6,(ix+n),e
		case 0xB4:	RES_IDX(6);	H = tmp;				break;	//res 6,(ix+n),h
		case 0xB5:	RES_IDX(6);	L = tmp;				break;	//res 6,(ix+n),l
		case 0xB6:	RES_IDX(6);							break;	//res 6,(ix+n)
		case 0xB7:	RES_IDX(6);	A = tmp;				break;	//res 6,(ix+n),a
		case 0xB8:	RES_IDX(7);	B = tmp;				break;	//res 7,(ix+n),b
		case 0xB9:	RES_IDX(7);	C = tmp;				break;	//res 7,(ix+n),c
		case 0xBA:	RES_IDX(7);	D = tmp;				break;	//res 7,(ix+n),d
		case 0xBB:	RES_IDX(7);	E = tmp;				break;	//res 7,(ix+n),e
		case 0xBC:	RES_IDX(7);	H = tmp;				break;	//res 7,(ix+n),h
		case 0xBD:	RES_IDX(7);	L = tmp;				break;	//res 7,(ix+n),l
		case 0xBE:	RES_IDX(7);							break;	//res 7,(ix+n)
		case 0xBF:	RES_IDX(7);	A = tmp;				break;	//res 7,(ix+n),a
		case 0xC0:	SET_IDX(0);	B = tmp;				break;	//set 0,(ix+n),b
		case 0xC1:	SET_IDX(0);	C = tmp;				break;	//set 0,(ix+n),c
		case 0xC2:	SET_IDX(0);	D = tmp;				break;	//set 0,(ix+n),d
		case 0xC3:	SET_IDX(0);	E = tmp;				break;	//set 0,(ix+n),e
		case 0xC4:	SET_IDX(0);	H = tmp;				break;	//set 0,(ix+n),h
		case 0xC5:	SET_IDX(0);	L = tmp;				break;	//set 0,(ix+n),l
		case 0xC6:	SET_IDX(0);							break;	//set 0,(ix+n)
		case 0xC7:	SET_IDX(0);	A = tmp;				break;	//set 0,(ix+n),a
		case 0xC8:	SET_IDX(1);	B = tmp;				break;	//set 1,(ix+n),b
		case 0xC9:	SET_IDX(1);	C = tmp;				break;	//set 1,(ix+n),c
		case 0xCA:	SET_IDX(1);	D = tmp;				break;	//set 1,(ix+n),d
		case 0xCB:	SET_IDX(1);	E = tmp;				break;	//set 1,(ix+n),e
		case 0xCC:	SET_IDX(1);	H = tmp;				break;	//set 1,(ix+n),h
		case 0xCD:	SET_IDX(1);	L = tmp;				break;	//set 1,(ix+n),l
		case 0xCE:	SET_IDX(1);							break;	//set 1,(ix+n)
		case 0xCF:	SET_IDX(1);	A = tmp;				break;	//set 1,(ix+n),a
		case 0xD0:	SET_IDX(2);	B = tmp;				break;	//set 2,(ix+n),b
		case 0xD1:	SET_IDX(2);	C = tmp;				break;	//set 2,(ix+n),c
		case 0xD2:	SET_IDX(2);	D = tmp;				break;	//set 2,(ix+n),d
		case 0xD3:	SET_IDX(2);	E = tmp;				break;	//set 2,(ix+n),e
		case 0xD4:	SET_IDX(2);	H = tmp;				break;	//set 2,(ix+n),h
		case 0xD5:	SET_IDX(2);	L = tmp;				break;	//set 2,(ix+n),l
		case 0xD6:	SET_IDX(2);							break;	//set 2,(ix+n)
		case 0xD7:	SET_IDX(2);	A = tmp;				break;	//set 2,(ix+n),a
		case 0xD8:	SET_IDX(3);	B = tmp;				break;	//set 3,(ix+n),b
		case 0xD9:	SET_IDX(3);	C = tmp;				break;	//set 3,(ix+n),c
		case 0xDA:	SET_IDX(3);	D = tmp;				break;	//set 3,(ix+n),d
		case 0xDB:	SET_IDX(3);	E = tmp;				break;	//set 3,(ix+n),e
		case 0xDC:	SET_IDX(3);	H = tmp;				break;	//set 3,(ix+n),h
		case 0xDD:	SET_IDX(3);	L = tmp;				break;	//set 3,(ix+n),l
		case 0xDE:	SET_IDX(3);							break;	//set 3,(ix+n)
		case 0xDF:	SET_IDX(3);	A = tmp;				break;	//set 3,(ix+n),a
		case 0xE0:	SET_IDX(4);	B = tmp;				break;	//set 4,(ix+n),b
		case 0xE1:	SET_IDX(4);	C = tmp;				break;	//set 4,(ix+n),c
		case 0xE2:	SET_IDX(4);	D = tmp;				break;	//set 4,(ix+n),d
		case 0xE3:	SET_IDX(4);	E = tmp;				break;	//set 4,(ix+n),e
		case 0xE4:	SET_IDX(4);	H = tmp;				break;	//set 4,(ix+n),h
		case 0xE5:	SET_IDX(4);	L = tmp;				break;	//set 4,(ix+n),l
		case 0xE6:	SET_IDX(4);							break;	//set 4,(ix+n)
		case 0xE7:	SET_IDX(4);	A = tmp;				break;	//set 4,(ix+n),a
		case 0xE8:	SET_IDX(5);	B = tmp;				break;	//set 5,(ix+n),b
		case 0xE9:	SET_IDX(5);	C = tmp;				break;	//set 5,(ix+n),c
		case 0xEA:	SET_IDX(5);	D = tmp;				break;	//set 5,(ix+n),d
		case 0xEB:	SET_IDX(5);	E = tmp;				break;	//set 5,(ix+n),e
		case 0xEC:	SET_IDX(5);	H = tmp;				break;	//set 5,(ix+n),h
		case 0xED:	SET_IDX(5);	L = tmp;				break;	//set 5,(ix+n),l
		case 0xEE:	SET_IDX(5);							break;	//set 5,(ix+n)
		case 0xEF:	SET_IDX(5);	A = tmp;				break;	//set 5,(ix+n),a
		case 0xF0:	SET_IDX(6);	B = tmp;				break;	//set 6,(ix+n),b
		case 0xF1:	SET_IDX(6);	C = tmp;				break;	//set 6,(ix+n),c
		case 0xF2:	SET_IDX(6);	D = tmp;				break;	//set 6,(ix+n),d
		case 0xF3:	SET_IDX(6);	E = tmp;				break;	//set 6,(ix+n),e
		case 0xF4:	SET_IDX(6);	H = tmp;				break;	//set 6,(ix+n),h
		case 0xF5:	SET_IDX(6);	L = tmp;				break;	//set 6,(ix+n),l
		case 0xF6:	SET_IDX(6);							break;	//set 6,(ix+n)
		case 0xF7:	SET_IDX(6);	A = tmp;				break;	//set 6,(ix+n),a
		case 0xF8:	SET_IDX(7);	B = tmp;				break;	//set 7,(ix+n),b
		case 0xF9:	SET_IDX(7);	C = tmp;				break;	//set 7,(ix+n),c
		case 0xFA:	SET_IDX(7);	D = tmp;				break;	//set 7,(ix+n),d
		case 0xFB:	SET_IDX(7);	E = tmp;				break;	//set 7,(ix+n),e
		case 0xFC:	SET_IDX(7);	H = tmp;				break;	//set 7,(ix+n),h
		case 0xFD:	SET_IDX(7);	L = tmp;				break;	//set 7,(ix+n),l
		case 0xFE:	SET_IDX(7);							break;	//set 7,(ix+n)
		case 0xFF:	SET_IDX(7);	A = tmp;				break;	//set 7,(ix+n),a
		default:
			message("bad DDCB opcode = $%02X\n",opcode);
			return(1);
	}
	return(0);
}
